// 引入环境配置
const { getBaseUrl } = require('../config/env');
const BaseUrl = getBaseUrl();


// 通用请求封装
const request = (method, url, data = {}, config = {}) => {
  let targetUrl = BaseUrl + url;
  return new Promise((resolve, reject) => {
    wx.request({
      url: targetUrl,
      method: method,
      data: data,
      header: {
        'Content-Type': 'application/json',
        ...config.headers
      },
      success: (res) => resolve(res.data),
      fail: (err) => reject(err)
    });
  });
};

// GET请求
export const get = (url, params = {}, config = {}) => {
  return request('GET', url, params, config);
};

// POST请求
export const post = (url, data = {}, config = {}) => {
  return request('POST', url, data, config);
};



